﻿using Dapper;
using OMG.Fill.Mulberry.Model.Ent;
using ProjectShare;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace OMG.Fill.Mulberry.Service
{
    /// <summary>
    /// 表10县生产信息调查统计表T_MulProdInfoChart通用操作类
    /// </summary>
    public class MulProdInfoCharts
    {
        /// <summary>
        /// 添加
        /// </summary>
        public virtual ResResult<int> AddInfo(MulProdInfoChartEntity model) {
            ResResult<int> obj = new ResResult<int>();
            string strSql = @"INSERT INTO dbo.T_MulProdInfoChart";
            strSql += "(";
            strSql += "Id,";
            strSql += "ReportId,";
            strSql += "NumTownship,";
            strSql += "NumTownshipName,";
            strSql += "NumVillage,";
            strSql += "NumVillageName,";
            strSql += "MulHouseholds,";
            strSql += "AnnualSilkwormOne,";
            strSql += "AnnualSilkwormTwo,";
            strSql += "AnnualSilkwormThree,";
            strSql += "AnnualSilkwormFour,";
            strSql += "TecPersonTotalNum,";
            strSql += "TecPersonAllInNum,";
            strSql += "ManNum,";
            strSql += "WomanNum,";
            strSql += "AgeOne,";
            strSql += "AgeTwo,";
            strSql += "AgeThree,";
            strSql += "AgeFour,";
            strSql += "EduLevelOne,";
            strSql += "EduLeveTwo,";
            strSql += "EduLevelThree,";
            strSql += "EduLevelFour,";
            strSql += "TitleOne,";
            strSql += "TitleTwo,";
            strSql += "TitleThree,";
            strSql += "TitleFour,";
            strSql += "IncuRoomNum,";
            strSql += "IncuRoomArea,";
            strSql += "JiCuiqingPower,";
            strSql += "YearsOfIncu,";
            strSql += "SilkwormSpots,";
            strSql += "SilkwormArea,";
            strSql += "QuaternaryFertility,";
            strSql += "AnnualTotalFertility,";
            strSql += "LargeCocoonNum,";
            strSql += "LargeCocoonArea,";
            strSql += "LaborSavingRearTable,";
            strSql += "GridCluster,";
            strSql += "CocoonStation,";
            strSql += "CocoonStationArea,";
            strSql += "SeasonalDryCapacity,";
            strSql += "CircularDryMachine)";
            //strSql += "ReelingEnterprise,";
            //strSql += "ReelingCapacityOne,";
            //strSql += "ReelingCapacityTwo,";
            //strSql += "ReelingCapacityThree,";
            //strSql += "ReelingCapacityFour,";
            //strSql += "SilkwormField,";
            //strSql += "ThroughPut,";
            //strSql += "SilkEnterprise,";
            //strSql += "ProcessedSilkQuilt,";
            //strSql += "Other,";
            //strSql += "OtherThroughPut)";
            strSql += " values(";
            strSql += "@Id,";
            strSql += "@ReportId,";
            strSql += "@NumTownship,";
            strSql += "@NumTownshipName,";
            strSql += "@NumVillage,";
            strSql += "@NumVillageName,";
            strSql += "@MulHouseholds,";
            strSql += "@AnnualSilkwormOne,";
            strSql += "@AnnualSilkwormTwo,";
            strSql += "@AnnualSilkwormThree,";
            strSql += "@AnnualSilkwormFour,";
            strSql += "@TecPersonTotalNum,";
            strSql += "@TecPersonAllInNum,";
            strSql += "@ManNum,";
            strSql += "@WomanNum,";
            strSql += "@AgeOne,";
            strSql += "@AgeTwo,";
            strSql += "@AgeThree,";
            strSql += "@AgeFour,";
            strSql += "@EduLevelOne,";
            strSql += "@EduLeveTwo,";
            strSql += "@EduLevelThree,";
            strSql += "@EduLevelFour,";
            strSql += "@TitleOne,";
            strSql += "@TitleTwo,";
            strSql += "@TitleThree,";
            strSql += "@TitleFour,";
            strSql += "@IncuRoomNum,";
            strSql += "@IncuRoomArea,";
            strSql += "@JiCuiqingPower,";
            strSql += "@YearsOfIncu,";
            strSql += "@SilkwormSpots,";
            strSql += "@SilkwormArea,";
            strSql += "@QuaternaryFertility,";
            strSql += "@AnnualTotalFertility,";
            strSql += "@LargeCocoonNum,";
            strSql += "@LargeCocoonArea,";
            strSql += "@LaborSavingRearTable,";
            strSql += "@GridCluster,";
            strSql += "@CocoonStation,";
            strSql += "@CocoonStationArea,";
            strSql += "@SeasonalDryCapacity,";
            strSql += "@CircularDryMachine)";
            //strSql += "@ReelingEnterprise,";
            //strSql += "@ReelingCapacityOne,";
            //strSql += "@ReelingCapacityTwo,";
            //strSql += "@ReelingCapacityThree,";
            //strSql += "@ReelingCapacityFour,";
            //strSql += "@SilkwormField,";
            //strSql += "@ThroughPut,";
            //strSql += "@SilkEnterprise,";
            //strSql += "@ProcessedSilkQuilt,";
            //strSql += "@Other,";
            //strSql += "@OtherThroughPut)";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    model.Id= CustomFun.GetGuid();
                    int result = dbCon.Execute(strSql, model);
                    if (result > 0)
                    {
                        obj.model = result;
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "添加成功！";
                    }
                    else
                    {
                        obj.model = result;
                        obj.status = DefaultKey.InfoResult;
                        obj.message = "添加失败！数量为:" + result;
                    }
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("新增表10县生产信息调查统计表T_MulProdInfoChart对象信息失败", ex);
                return obj;
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        public virtual ResResult<int> UpdateInfo(MulProdInfoChartEntity model)
        {
            ResResult<int> obj = new ResResult<int>();
            string strSql = @"UPDATE dbo.T_MulProdInfoChart set ";
            strSql += "ReportId = @ReportId,";
            strSql += "NumTownship = @NumTownship,";
            strSql += "NumTownshipName = @NumTownshipName,";
            strSql += "NumVillage = @NumVillage,";
            strSql += "NumVillageName = @NumVillageName,";
            strSql += "MulHouseholds = @MulHouseholds,";
            strSql += "AnnualSilkwormOne = @AnnualSilkwormOne,";
            strSql += "AnnualSilkwormTwo = @AnnualSilkwormTwo,";
            strSql += "AnnualSilkwormThree = @AnnualSilkwormThree,";
            strSql += "AnnualSilkwormFour = @AnnualSilkwormFour,";
            strSql += "TecPersonTotalNum = @TecPersonTotalNum,";
            strSql += "TecPersonAllInNum = @TecPersonAllInNum,";
            strSql += "ManNum = @ManNum,";
            strSql += "WomanNum = @WomanNum,";
            strSql += "AgeOne = @AgeOne,";
            strSql += "AgeTwo = @AgeTwo,";
            strSql += "AgeThree = @AgeThree,";
            strSql += "AgeFour = @AgeFour,";
            strSql += "EduLevelOne = @EduLevelOne,";
            strSql += "EduLeveTwo = @EduLeveTwo,";
            strSql += "EduLevelThree = @EduLevelThree,";
            strSql += "EduLevelFour = @EduLevelFour,";
            strSql += "TitleOne = @TitleOne,";
            strSql += "TitleTwo = @TitleTwo,";
            strSql += "TitleThree = @TitleThree,";
            strSql += "TitleFour = @TitleFour,";
            strSql += "IncuRoomNum = @IncuRoomNum,";
            strSql += "IncuRoomArea = @IncuRoomArea,";
            strSql += "JiCuiqingPower = @JiCuiqingPower,";
            strSql += "YearsOfIncu = @YearsOfIncu,";
            strSql += "SilkwormSpots = @SilkwormSpots,";
            strSql += "SilkwormArea = @SilkwormArea,";
            strSql += "QuaternaryFertility = @QuaternaryFertility,";
            strSql += "AnnualTotalFertility = @AnnualTotalFertility,";
            strSql += "LargeCocoonNum = @LargeCocoonNum,";
            strSql += "LargeCocoonArea = @LargeCocoonArea,";
            strSql += "LaborSavingRearTable = @LaborSavingRearTable,";
            strSql += "GridCluster = @GridCluster,";
            strSql += "CocoonStation = @CocoonStation,";
            strSql += "CocoonStationArea = @CocoonStationArea,";
            strSql += "SeasonalDryCapacity = @SeasonalDryCapacity,";
            strSql += "CircularDryMachine = @CircularDryMachine";
            //strSql += "ReelingEnterprise = @ReelingEnterprise,";
            //strSql += "ReelingCapacityOne = @ReelingCapacityOne,";
            //strSql += "ReelingCapacityTwo = @ReelingCapacityTwo,";
            //strSql += "ReelingCapacityThree = @ReelingCapacityThree,";
            //strSql += "ReelingCapacityFour = @ReelingCapacityFour,";
            //strSql += "SilkwormField = @SilkwormField,";
            //strSql += "ThroughPut = @ThroughPut,";
            //strSql += "SilkEnterprise = @SilkEnterprise,";
            //strSql += "ProcessedSilkQuilt = @ProcessedSilkQuilt,";
            //strSql += "Other = @Other,";
            //strSql += "OtherThroughPut = @OtherThroughPut";
            strSql += " where Id = @Id";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    int result = dbCon.Execute(strSql, model);
                    if (result > 0)
                    {
                        obj.model = result;
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "更新成功！";
                    }
                    else
                    {
                        obj.model = result;
                        obj.status = DefaultKey.InfoResult;
                        obj.message = "更新失败！数量为:" + result;
                    }
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("更新表10县生产信息调查统计表T_MulProdInfoChart对象信息失败", ex);
                return obj;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        public virtual ResResult<int> DeleteInfo(string id)
        {
            ResResult<int> obj = new ResResult<int>();
            string strSql = @"delete from dbo.T_MulProdInfoChart where Id = @Id";
            int result;
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    result = dbCon.Execute(strSql, new { Id = id });
                    if (result > 0)
                    {
                        obj.model = result;
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "删除成功！";
                    }
                    else
                    {
                        obj.model = result;
                        obj.status = DefaultKey.InfoResult;
                        obj.message = "删除失败！数量为:" + result;
                    }
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("删除表10县生产信息调查统计表T_MulProdInfoChart对象信息失败", ex);
                return obj;
            }
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        public virtual ResResult<int> DeleteBatch(string[] ids)
        {
            ResResult<int> obj = new ResResult<int>();
            string strIds = string.Join(",", ids.Select(x => x.ToString()).ToArray());
            string strSql = @"delete from dbo.T_MulProdInfoChart where Id in @ids";
            var dynamicSqlParam = new DynamicParameters();
            dynamicSqlParam.Add("ids", ids.ToArray(), null, null, null);
            int result;
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    result = dbCon.Execute(strSql, dynamicSqlParam);
                    if (result > 0)
                    {
                        obj.model = result;
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "删除成功！";
                    }
                    else
                    {
                        obj.status = DefaultKey.InfoResult;
                        obj.message = "删除失败！数量为:" + result;
                    }
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("获取数据字典表批量删除表10县生产信息调查统计表T_MulProdInfoChart表失败", ex);
                obj.message = ex.ToString().Trim();
                obj.status = DefaultKey.ErrorResult;
                return obj;
            }
        }
        /// <summary>
        /// 获取指定对象
        /// </summary>
        public virtual ResResult<MulProdInfoChartEntity> GetModel(string id) {
            ResResult<MulProdInfoChartEntity> obj = new ResResult<MulProdInfoChartEntity>();
            string strSql = @"select * from dbo.T_MulProdInfoChart where Id = @Id";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    obj.model = dbCon.Query<MulProdInfoChartEntity>(strSql, new { Id = id }).FirstOrDefault();
                    obj.status = DefaultKey.SuccessResult;
                    obj.message = "获取成功！";
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("获取表10县生产信息调查统计表T_MulProdInfoChart对象信息失败", ex);
                return obj;
            }
        }
        /// <summary>
        /// 获取全部列表
        /// </summary>
        /// <returns></returns>
        public virtual ResResult<List<MulProdInfoChartEntity>> GetList()
        {
            ResResult<List<MulProdInfoChartEntity>> obj = new ResResult<List<MulProdInfoChartEntity>>();
            string strSql = @"select * from dbo.T_MulProdInfoChart";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    obj.model = dbCon.Query<MulProdInfoChartEntity>(strSql).ToList();
                    obj.status = DefaultKey.SuccessResult;
                    obj.message = "获取成功！";
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("更新表10县生产信息调查统计表T_MulProdInfoChart对象信息失败", ex);
                return obj;
            }
        }
    }
}